<?php


namespace App\Controller\Api\V1;

use App\Common\BeseController;
use App\Model\Mysql\LabelModel;
use App\Model\Mysql\RenovationModel;
use App\Model\Mysql\UserSearchModel;

class Index extends BeseController
{

    public function label()
    {

        $label = LabelModel::getlist(['status' => 1], ['id as label_id', 'name'], [], ['sort' => 'ASC', 'id' => 'DESC']);

        $data = [
            ['label_id' => 0, 'name' => '全部'],
            ['label_id' => -1, 'name' => '热门推荐'],
            ['label_id' => -2, 'name' => '奖励金额'],
            ['label_id' => -3, 'name' => '日结'],
        ];

        return $this->responseSuccess('请求成功', array_merge($data, $label));
    }


    public function renovation()
    {

        $banner = RenovationModel::getList(['position' => 'index_banner', 'status' => 1], ['image']);

        $video = RenovationModel::getValue(['position' => 'index_video', 'status' => 1], 'video') ?? '';


        return $this->responseSuccess('请求成功', ['banner' => $banner, 'video' => $video]);
    }

    public function search()
    {

        $input = $this->input;

        $userId = $input['user']['id'] ?? 1;

        $search = UserSearchModel::getlist(['user_id' => $userId], ['id', 'search'], [], ['search_time' => 'DESC']);

        return $this->responseSuccess('请求成功', $search);
    }

    public function searchDelete()
    {

        $input = $this->input;

        $userId = $input['user']['id'] ?? 1;

        $where = ['user_id' => $userId];

        if (!empty($input['id'])) {
            $where['id'] = $input['id'];

        }
        $res = UserSearchModel::deleteData($where);

        if (!$res) return $this->responseError('操作失败');

        return $this->responseSuccess('操作成功');
    }


}